/*
 * hd44780.h
 *
 *  Created on: Nov 21, 2010
 *      Author: Orlando Arias
 *     License: GPL v3
 *
 *    hd44870-spi
 *    Copyright (C) 2010  Orlando Arias
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef HD44780_H_
#define HD44780_H_

#include <inttypes.h>
#include <stdio.h>
#include <avr/io.h>

#include "hd_handler.h"

#define lcd_createStream() FDEV_SETUP_STREAM(lcd_writeChar, NULL, _FDEV_SETUP_WRITE)

typedef enum _command_set {
	CLEAR = 0x01,						// clear screen and set cursor to 0x00
	MOVE_HOME = 0x02,					// set cursor to 0x00
	EM_DECREMENT_OFF = 0x04,			// move cursor left after write to DDRAM
	EM_DECREMENT_ON = 0x05,				// move text right after write to DDRAM
	EM_INCREMENT_OFF = 0x06,			// move cursor left after write to DDRAM
	EM_INCREMENT_ON = 0x07,				// move text right after write to DDRAM
	BLANK_DISPLAY = 0x08,				// display on/off
	CURSOR_INVISIBLE = 0x0C,			// cursor is not visible
	CURSOR_VISIBLE_BLOCK = 0x0D,		// cursor visible as alternating block
	CURSOR_VISIBLE_UNDERLINE = 0x0E,	// cursor visible as underline
	CURSOR_VISIBLE_ALT = 0x0F,			// cursor visible as blinking block/underline
	MOVE_LEFT = 0x10,					// move cursor left
	MOVE_RIGHT = 0x14,					// move cursor right
	SCROLL_LEFT = 0x18,					// scroll DDRAM left
	SCROLL_RIGHT = 0x1E,				// scroll DDRAM right
	SET_CGRAM = 0x40,					// sets cursor position on CGRAM (or pos << 3 with function)
	SET_DDRAM = 0x80					// sets cursor position on DDRAM (or with function)
} command;

void lcd_init();
void lcd_sendCommand(command cmd);
int lcd_writeChar(char c, FILE *unused);

#endif /* HD44780_H_ */
